package com.google.code.p.restrpc.client.proxy;

import com.google.code.p.restrpc.RpcException;
import com.google.code.p.restrpc.RpcResponse;
import com.google.code.p.restrpc.client.RpcResponseHandler;

/**
 * @author dz
 */
public class AsyncRpcResponseHandler implements RpcResponseHandler {
    
    public static final AsyncRpcResponseHandler instance = new AsyncRpcResponseHandler();
    
    /**
     * @return for async invoke , nothing reguired to returned , null if the async appended to the server async execute queue.
     *         otherwise throws exception.
     */
    public Object handle(RpcResponse response, Class clazz) throws RpcException {
        if (!response.isSucceed() && response.getFault() != null) {
            if (response.getFault().isBizError()) {
                throw new RpcBizException(response.getFault().getMessage(),
                                          response.getFault().getCode(),
                                          response.getFault().getDetail());
            }
            else {
                throw new RpcInvokeException(response.getFault().getMessage(),
                                             response.getFault().getCode(),
                                             response.getFault().getDetail());
            }
        }
        
        //for async invoke , nothing reguired to returned
        //only 
        return null;
    }
}
